//
//  NSNumber+Add.m
//  AtCar
//
//  Created by 代佳宏 on 2021/1/5.
//  Copyright © 2021 车一转. All rights reserved.
//

#import "NSNumber+Add.h"

@implementation NSNumber (Add)

/// 转成字符串，保留dot位小数,小数点后的是0，则抹去，如：0.10 -> 0.1, 1.00 -> 1
/// @param dot 保留小数位数
- (NSString *)changeToStringWithDot:(NSInteger)dot {
    NSNumberFormatter * formatter = [[NSNumberFormatter alloc] init];
    [formatter setNumberStyle:NSNumberFormatterDecimalStyle];
    NSMutableArray *tempValue = @[].mutableCopy;
    while (dot > 0) {
        [tempValue addObject:@"#"];
        dot -= 1;
    }
    [formatter setPositiveFormat:[NSString stringWithFormat:@"###.%@",[tempValue componentsJoinedByString:@""]]];
    NSString *value = [formatter stringFromNumber:self];
    return value;
}
/// 转成字符串，保留dot位小数,小数点后的是0，则抹去，如：0.10 -> 0.1, 1.00 -> 1
/// @param number 转换前 的数字
/// @param dot 保留小数位数
+ (NSString *)changeNumber:(CGFloat)number toStringWithDot:(NSInteger)dot {
    return [@(number) changeToStringWithDot:dot];
}

@end
